using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace TSPLoader
{
    public class Point3D
    {
        public double x, y, z;
        public Point3D()
        {
            x = y = z = 0.0;
        }
        public Point3D(double X,double Y)
        {
            x = X;
            y = Y;
            z = 0.0;
        }
        public Point3D(double X, double Y, double Z)
        {
            x = X;
            y = Y;
            z = Z;
        }
    }
    public class Zone
    {
        private bool IsVariables;
        private int _variablenumber;
        //private static List<string> Variable;
        private double[,] points;
        private List<int> topology;

        private string _Title;
        private int _NumberOfNodes;
        private int _NumberOfElements;
        private string _ElementType;
        private Color _Color;
        private string _FEFormat;
        private List<string> _FEDuplist;
        private string _NodeValue;
        private List<string> _DataType;
        private int lineNO;
        private int topNO;
        

        public Zone()
        {
            topNO = lineNO = 0;
            IsVariables = false ;
            
        }


        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        public int NumberOfNodes
        {
            get { return _NumberOfNodes; }
            set { _NumberOfNodes = value; }
        }

        public int NumberOfElements
        {
            get { return _NumberOfElements; }
            set 
            {
                _NumberOfElements = value;
                //points = new double[_NumberOfNodes, Variable.Count];
                
            }
        }

        public string ElementType
        {
            get { return _ElementType; }
            set { _ElementType = value; }
        }

        public Color Color
        {
            get { return _Color; }
            set { _Color = value; }
        }

        public string FEFormat
        {
            get { return _FEFormat; }
            set { _FEFormat = value; }
        }

        public List<string> FEDuplist
        {
            get { return _FEDuplist; }
            set { _FEDuplist = value; }
        }

        public string NodeValue
        {
            get { return _NodeValue; }
            set { _NodeValue = value; }
        }

        public List<string> DataType
        {
            get { return _DataType; }
            set { _DataType = value; }
        }



        internal void FillPointsLine(string[] values)
        {
            if (!IsVariables && (_FEFormat == "FEPOINT" || _FEFormat==""))
            {
                points = new double[_NumberOfNodes, values.Length];
                _variablenumber = values.Length;
                IsVariables = true;
            }
            else if (!IsVariables && _FEFormat == "FEBLOCK")
            {
                points = new double[_NumberOfNodes, FileHeader.Variables.Count];
                _variablenumber = FileHeader.Variables.Count;
                IsVariables = true;
            }

            

            if (_FEFormat == "FEPOINT")
            {
                for (int i = 0; i < values.Length; i++)
                    points[lineNO, i] = double.Parse(values[i]);
                lineNO++;
            }
            else if (_FEFormat == "FEBLOCK")
            {
                for (int i = 0; i < values.Length; i++)
                    points[i, lineNO] = double.Parse(values[i]);
                lineNO++;
            }
        }
        internal void FillTopology(string[] values)
        {
            topology = new List<int>();
                for (int i = 0; i < values.Length; i++)
                    topology.Add(int.Parse(values[i]));
        }

        public List<Point3D> ZoneNodes()
        {

                List<Point3D> l = new List<Point3D>();
                for (int i = 0; i < _NumberOfNodes; i++)
                {
                    if(_variablenumber>3)
                        l.Add(new Point3D(points[i, 0], points[i, 1], points[i, 2]));
                    else
                        l.Add(new Point3D(points[i, 0], points[i, 1]));
                }
                return l;
        }

        public List<int> GetTopology()
        {
            return topology;
        }

        public List<double> NodeValues(int NodeNumber)
        {
            List<double> l = new List<double>();
            if (_variablenumber > 3)
            {
                for(int i=3;i<_variablenumber;i++)
                    l.Add(points[NodeNumber,i]);
                return l;
            }
            else if(_variablenumber > 2)
            {
                for(int i=2;i<_variablenumber;i++)
                    l.Add(points[NodeNumber,i]);
                return l;
            }
            return l;
        }


    }
}
